package com.it.gw.modules.water.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.it.data.network.req.PumpRecordDto
import com.it.data.network.req.ShouBuRecordDto
import com.it.gw.databinding.ItemPumpBinding
import com.it.gw.databinding.ItemShoubuBinding


class ShouBuItemAdapter(
    var context: Context,
    var listener: ((ShouBuRecordDto) -> Unit)? = null,
    var datas: List<ShouBuRecordDto>
) : RecyclerView.Adapter<ShouBuItemAdapter.ViewHolder>() {
    companion object {
        const val TAG = "ShouBuItemAdapter"
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        val binding = ItemShoubuBinding.inflate(LayoutInflater.from(parent.context))
        return ViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {
        val data = datas[position]
        Log.d(TAG, "onBindViewHolder: $data")
        holder.binding.one.text = "${position + 1}"
        holder.binding.two.text = data.sbmc
        holder.binding.three.text = data.sblx
        holder.binding.four.text = data.sztcdm

        holder.binding.root.setOnClickListener {
            listener?.invoke(data)
        }


    }

    override fun getItemCount() = datas.size

    class ViewHolder(val binding: ItemShoubuBinding) :
        RecyclerView.ViewHolder(binding.root)
}